package com.esd.csair;

import java.io.IOException;
import java.net.MalformedURLException;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;

import com.gargoylesoftware.htmlunit.BrowserVersion;
import com.gargoylesoftware.htmlunit.FailingHttpStatusCodeException;
import com.gargoylesoftware.htmlunit.NicelyResynchronizingAjaxController;
import com.gargoylesoftware.htmlunit.WebClient;
import com.gargoylesoftware.htmlunit.WebResponse;
import com.gargoylesoftware.htmlunit.html.HtmlDivision;
import com.gargoylesoftware.htmlunit.html.HtmlElement;
import com.gargoylesoftware.htmlunit.html.HtmlListItem;
import com.gargoylesoftware.htmlunit.html.HtmlPage;

import net.sf.json.JSONObject;

public class test2 {
	public static void main(String[] args) {

		long l = System.currentTimeMillis();
		// TODO Auto-generated method stub
		// http://b2c.csair.com/B2C40/checkLogin/jaxb/checkLogin.ao
		WebClient webClient = new WebClient(BrowserVersion.CHROME);// 设置浏览器的User-Agent
		webClient.setJavaScriptTimeout(10000);// 设置JS执行的超时时间
		webClient.getOptions().setThrowExceptionOnScriptError(false);// 当JS执行出错的时候是否抛出异常
		webClient.getOptions().setThrowExceptionOnFailingStatusCode(false);// 当HTTP的状态非200时是否抛出异常
		webClient.getOptions().setTimeout(30000);// 设置“浏览器”的请求超时时间
		webClient.getOptions().setCssEnabled(false);// 是否启用CSS
		webClient.getOptions().setJavaScriptEnabled(true); // 很重要，启用JS
		webClient.waitForBackgroundJavaScript(30000);// 设置JS后台等待执行时间
		webClient.setAjaxController(new NicelyResynchronizingAjaxController());// 很重要，设置支持AJAX
		System.out.println(System.currentTimeMillis() - l);

		try {
			HtmlPage page = webClient.getPage("http://www.bjmtg.gov.cn/zwgk/zwgg/201708/t20170803_66804.html");
			System.out.println(page.asXml());
			
		} catch (FailingHttpStatusCodeException | IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

	}

}
